package cn.jietuo.bio;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

/**
 * @author zhangx & jietuo_zx@163.com
 * @version 1.0
 * @date 2021/2/26
 * @description: socket 客户端
 */
public class SocketClient {

    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("localhost",9000);
        // 向服务器端发送信息
        socket.getOutputStream().write("你好呀".getBytes());
        socket.getOutputStream().flush();
        byte[] bytes = new byte[1024];
        InputStream socketInputStream = socket.getInputStream();
        int read = socketInputStream.read(bytes);
        if (read != -1){
            System.out.println("接收到服务端的信息："+ new String(bytes,0,read));
        }
        socket.close();
    }

}
